
#ifndef BUFFER_H_
#define BUFFER_H_

#ifdef _cplusplus
extern "C" {
#endif

typedef struct buffer {
	int 	id;
	char* data;
	int	size;
	int	writeIndex;
	int   readIndex;
} buffer;


struct buffer* initBuffer(int initSize);
void destroyBuffer(struct buffer* buf);

char* getWriteIndexBuffer(struct buffer* buf);
char* getReadIndexBuffer(struct buffer* buf);

void moveWriteIndexBuffer(struct buffer* buf, int moveLen);
void moveReadIndexBuffer(struct buffer* buf, int moveLen);

void appendBuffer(struct buffer* buf, const char* data, int dataLen);
void prependBuffer(struct buffer* buf, const char* data, int dataLen);

int expandBuffer(struct buffer* buf);

int getReadableBytesBuffer(struct buffer* buf);
int getWriteableBytesBuffer(struct buffer* buf);

void retrieveAllBuffer(struct buffer* buf);
int prependableBytesBuffer(struct buffer* buf);

char* beginBuffer(struct buffer* buf);

#ifdef _cplusplus
}
#endif

#endif /* BUFFER_H_ */
